#-*- coding: utf-8 -*-

import os
# in python3
# import configparser 
import ConfigParser as configparser

cfg_file = "config.ini"

cfg_str = """
[test 1]
ca = 23
bb = adf
"""

with open(cfg_file, "w") as ofs:
    ofs.write(cfg_str)


conf = configparser.ConfigParser()
conf.read(cfg_file)



# # 当前文件路径
# proDir = os.path.split(os.path.realpath(__file__))[0]
# # 在当前文件路径下查找.ini文件
# configPath = os.path.join(proDir, "config.ini")
# print(configPath)

# conf = configparser.ConfigParser()

# # 读取.ini文件
# conf.read(configPath)
# # get()函数读取section里的参数值
# name = conf.get("section1","name")
# print(name)

for section in conf.sections():
    print "====="
    print section
    print conf.options(section)
    for opt in conf.options(section):
        print opt, "=",  conf.get(section, opt)
    print conf.items(section)

# print(conf.sections())
# print(conf.options('section1'))
# print(conf.items('section1'))
